<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .hour,
    .minute,
    .second {
      width: 50px;
      height: 50px;
      display: inline-block;
      background-color: black;
      color: aliceblue;
      line-height: 30px;
      text-align: center;
    }
  </style>
</head>

<body>

  <span class="hour"></span>
  <span class="minute"></span>
  <span class="second"></span>

  <script>
    window.addEventListener('load', function () {
      //1.获取元素
      var hour = document.querySelector('.hour');
      var minute = document.querySelector('.minute');
      var second = document.querySelector('.second');
      var day = document.querySelector('.day');

      var shu = +new Date('2023-6-30 18:20:00');//用户输入的毫秒数
      js()//我们先调用一次这个函数，防止第一次刷新页面有空白
      //2.开启定时器
      var s = setInterval(js, 1000)
      function js(time) {
        var xian = +new Date();
        var times = (shu - xian) / 1000;
        // var t = parseInt(times / 60 / 60 / 24);
        // t = t < 10 ? '0' + t : t;
        // hour.innerHTML = t;
        var s = parseInt(times / 60 / 60 % 24);
        s = s < 10 ? '0' + s : s;
        hour.innerHTML = s;
        var f = parseInt(times / 60 % 60);
        minute.innerHTML = f
        f = f < 10 ? '0' + f : f;
        var m = parseInt(times % 60);
        second.innerHTML = m;
        m = m < 10 ? '0' + m : m;
      }

    })
  </script>
</body>

</html>